﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PointAsLine
{
    public class PointF2G
    {
        public float X, Y;
        public int GroupIndex;
        public int PointIndex;

        public PointF2G(float x, float y)
        {
            X = x;
            Y = y;
        }

        public PointF2G(float x, float y,int groupIndex)
        {
            X = x;
            Y = y;
            this.GroupIndex = groupIndex;
        }

        public PointF ToPointF()
        {
            return new PointF(X, Y);
        }

        public bool Equals(PointF2G other)
        {
            if (other is null) return false;
            return Math.Abs(X - other.X) < 1e-10 && Math.Abs(Y - other.Y) < 1e-10;
        }

        public override bool Equals(object obj) => Equals(obj as PointF2G);

        public override int GetHashCode() => HashCode.Combine(Math.Round(X, 5), Math.Round(Y, 5));

        public static bool operator ==(PointF2G left, PointF2G right) => EqualityComparer<PointF2G>.Default.Equals(left, right);
        public static bool operator !=(PointF2G left, PointF2G right) => !(left == right);

        public override string ToString() => "X = " + X + " Y = " + Y + " ";

        internal string ToNearPosStr(double v)
        {
            return (float)(Math.Round(X * 2.0) / 2.0f) + "_" + (float)(Math.Round(Y * 2.0) / 2.0f);
        }
    }
}
